<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="utf-8"/>
    <title>个人信息</title>
    <link rel="stylesheet" type="text/css" href="css/public.css"/>
    <link rel="stylesheet" type="text/css" href="css/mygrxx.css"/>
    <script src="X-admin/lib/layui/layui.js"></script>
    <script src="X-admin/js/jquery.js"></script>
    <script src="X-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="X-admin/css/xadmin.css">
    <script src="js/command.js"></script>
</head>
<body>
<!------------------------------head------------------------------>
<div class="head" id="top">
</div>
<!------------------------------idea------------------------------>
<div class="address mt" id="add">
    <div class="wrapper clearfix">
        <a href="index.html" class="fl">首页</a>
        <span>/</span>
        <a href="lessors-mygrxx.html" class="on">个人中心</a>
    </div>
</div>

<!------------------------------Bott------------------------------>
<div class="Bott">
    <div class="wrapper clearfix">
        <div class="zuo fl">
            <h3>
                <a href="#"><img  src="img/default.jpeg" id="zuo-head" style="width: 120px;height: 120px;border-radius:60%"/></a>
                <p class="clearfix"><span class="fl" id="zuo-name">[羊羊羊]</span><span class="fr">[退出登录]</span></p>
            </h3>

            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;" style="color: black;font-weight: bold">帐户管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="lessors-mygrxx.html">个人信息</a></dd>
                        <dd><a href="lessors-remima.html">修改密码</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;" style="color: black;font-weight: bold">财务中心</a>
                    <dl class="layui-nav-child">
                        <dd><a href="lessors-fiance.html">财务细明</a></dd>
                        <dd><a href="lessors-fiance-dailyList.html">日报</a></dd>
                        <dd><a href="lessors-fiance-monthlyList.html">月报</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;" style="color: black;font-weight: bold">个人中心</a>
                    <dl class="layui-nav-child">
                        <dd><a href="lessors-station.html">我的工位</a></dd>
                        <dd><a href="lessors-order-completed.html">工位订单</a></dd>
                        <dd><a href="lessors-mygxin.html">我的活动</a></dd>
                    </dl>
                </li>
            </ul>

        </div>
        <div class="you fl">
            <h2>个人信息</h2>
            <div class="gxin">
                <div class="tx" id="avatar">
                    <div class="tx"><a><img src="img/default.jpeg" style="width: 120px;height: 120px;border-radius:60%" id="you-head"/>
                        <p></p></a></div>
                </div>

                <div class="xx">
                    <h3 class="clearfix"><strong class="fl">基础资料</strong><a href="#" class="fr" id="edit1">编辑</a></h3>
                    <div>姓名：<span id="name"></span></div>
                    <div>电话：<span id="phone"></span></div>
                    <div>邮箱：<span id="email"></span></div>
                    <div>地址：<span id="adress"></span></div>
                    <div>注册时间：<span id="crtime"></span></div>
                    <!--<div><span class="fl">账号地区：中国</span><a href="#" class="fr" id="edit2"></a></div>-->
                </div>
            </div>
        </div>
    </div>
</div>
<!--遮罩-->
<div class="mask"></div>
<!--编辑弹框-->
<div class="bj">
    <div class="clearfix"><a href="#" class="fr gb"><img src="img/icon4.png"/></a></div>
    <h3>编辑基础资料</h3>
    <form>
        <p><label>姓名：</label><input type="text" id="name1"/></p>
        <p><label>电话：</label><input type="text" id="phone1"/></p>
        <p></p>
        <p><label>邮箱：</label><input type="text" id="email1"/></p>
        <p><label>地址：</label><input type="text" id="adress1"/></p>
        <div class="bc">
            <input type="submit" lay-submit lay-filter="update" value="保存"/>
            <input type="button" value="取消"/>
        </div>
    </form>
</div>

<!--修改头像-->
<div class="avatar">
    <div class="clearfix"><a href="#" class="fr gb"><img src="img/icon4.png"/></a></div>
    <img src="img/default.jpeg" style="width: 120px;height: 120px;border-radius:60%" id="you-inside-head">
    <h3>修改头像</h3>
    <form>
        <h4 >请上传图片</h4>
                <input type="file" name="file" id="showImg" value="上传头像"/>
        <img id="putImg" src="img/default.jpeg" style="width: 120px;height: 120px;border-radius:60%"/>
        <p>jpg或png，大小不超100M</p>
        <input type="submit"  lay-submit lay-filter="updateHead" value="提交" />
    </form>

</div>
<!--返回顶部-->
<div class="gotop">
    <a href="#" class="dh">
        <dl>
            <dt><img src="img/gt2.png"/></dt>
            <dd>联系<br/>客服</dd>
        </dl>
    </a>
    <a href="lessors-mygrxx.html">
        <dl>
            <dt><img src="img/gt3.png"/></dt>
            <dd>个人<br/>中心</dd>
        </dl>
    </a>
    <a href="#" class="toptop" style="display: none">
        <dl>
            <dt><img src="img/gt4.png"/></dt>
            <dd>返回<br/>顶部</dd>
        </dl>
    </a>
    <p>400-800-8200</p>
</div>
<!--footer-->
<div class="footer" id="foot"></div>


<script src="js/jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/public.js" type="text/javascript" charset="utf-8"></script>
<script src="js/user.js" type="text/javascript" charset="utf-8"></script>
<script src="js/common.js"></script>

<script>
    var Address_Prefix_Lessors = "http://localhost:9200/api-lessors";
    $(function () {
        find();
        upload();
    });


    function upload() {
        /**
         * 图片上传
         */
        layui.use(['upload','form'],function () {
            var form = layui.form;
            var upload = layui.upload;
            upload.render({
                elem: '#showImg',//绑定元素
                url: Address_Prefix_Lessors + '/upload/file',//上传到后端接口
                done: function (res) {//上传完毕回调
                    console.log(res);
                    console.log(res.data);
                    sessionStorage.setItem("image", res.data);
                    $("#putImg").attr("src", res.data);
                },
                error: function () {
                    console.log("回调出错了!")
                    //请求异常回调
                }
            });

            form.on('submit(updateHead)', function () {
                var data = {
                    buhead : sessionStorage.getItem("image"),
                    busiid : sessionStorage.getItem("busiid")
                };

                console.log(data, "22222");
                $.ajax({
                    url: Address_Prefix_Lessors + '/business/data/updateHead',//地址：访问后台的地址
                    data: data,//前端传递给后台的数据
                    type: 'post',
                    async: false,
                    // xhrFields: {
                    // 	withCredentials: true
                    // },
                    // crossDomain: true,
                    dataType: 'json',//是后端传递到前端的数据格式
                    success: function (data) {//后端给前端的一个反馈
                        console.log(data);
                        if (data.code === 0) {
                            layer.msg("ok！",{time:1000},function () {
                                location.reload();
                            })
                        }
                    }
                });
                return false;
            })
        });
    }


    function find() {
        $.ajax({
            url: Address_Prefix_Lessors + "/business/data/findById",
            data: {id: sessionStorage.getItem("busiid")},
            dataType: 'json',
            type: 'get',
            async: false,
            success: function (data) {
                console.log(data);
                //基础资料
                $("#name").html(data.data.buname); 	   	   //名称
                $("#adress").html(data.data.adress);       //地址
                $("#email").html(data.data.bemail);        //地址
                $("#phone").html(data.data.bphone);        //电话
                $("#crtime").html(data.data.crtime);       //注册时间
                //左边-zuo
                $("#zuo-name").html(data.data.buname); //名称
                $("#zuo-head").attr("src", data.data.buhead); //头像
                //右边里-you
                $("#you-inside-head").attr("src", data.data.buhead); //头像
                //右边-you
                $("#you-head").attr("src", data.data.buhead); //头像

                // $("#zuo-head").html(data.data.buhead); //头像
                sessionStorage.setItem("data", JSON.stringify(data.data));
            }
        });
        return false;
    }

    layui.use('form', function () {
        var form = layui.form;
        var data = JSON.parse(sessionStorage.getItem('data'));
        console.log(data, 11111);
        console.log(data.buname);
        console.log(data.adress);
        console.log(data.bemail);
        console.log(data.bphone);
        $("#name1").val(data.buname); 	   	   //名称
        $("#adress1").val(data.adress);       //地址
        $("#email1").val(data.bemail);        //地址
        $("#phone1").val(data.bphone);        //电话

        form.on('submit(update)', function () {
            data.buname = $("#name1").val();
            data.bphone = $("#phone1").val();
            data.bemail = $("#email1").val();
            data.adress = $("#adress1").val();
            console.log(data, "22222");
            $.ajax({
                url: Address_Prefix_Lessors + '/business/data/update',//地址：访问后台的地址
                data: data,//前端传递给后台的数据
                type: 'post',
                async: false,
                // xhrFields: {
                // 	withCredentials: true
                // },
                // crossDomain: true,
                dataType: 'json',//是后端传递到前端的数据格式
                success: function (data) {//后端给前端的一个反馈
                    console.log(data);
                    if (data.code === 0) {
                        layer.msg("ok！",{time:1000},function () {
                            location.reload();
                        })
                    }
                }
            });
            return false;
        })
    });
</script>
</body>
</html>
